
#include "CTutorialState.h"

#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../Visual/VIN_BitMapFont.h"
#include "CGamePlayState.h"
#include "CMainMenuState.h"
#include "../Core/CGame.h"
#include "../Managers/InputManager.h"



CTutorialState::CTutorialState()
{
	Page = 0;
}

CTutorialState::~CTutorialState()
{

}

void CTutorialState::Enter()
{
	Page = 0;
	background = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/scroll.png");
	back = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/background.png");
	castle = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/castle.png");
	inHand = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/InHand.png");
	badguys = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/thebadguys.png");
	boom = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/trainer.png");
	weapons = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/theWeapons.png");
	gas = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/Koffing.png");
	pot = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/Pot.png");
	bigbow = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/ballista.png");
	bow = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/Archer.png");
	rock = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/Fat Tallnut.png");
	castle1 = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/castle1.png");
	castle2 = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/castle2.png");
	castle3 = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/castle3.png");
}


void CTutorialState::Exit()
{
	CSGD_TextureManager::GetInstance()->UnloadTexture(background);
	CSGD_TextureManager::GetInstance()->UnloadTexture(back);
	CSGD_TextureManager::GetInstance()->UnloadTexture(castle);
	CSGD_TextureManager::GetInstance()->UnloadTexture(inHand);
	CSGD_TextureManager::GetInstance()->UnloadTexture(badguys);
	CSGD_TextureManager::GetInstance()->UnloadTexture(boom);
	CSGD_TextureManager::GetInstance()->UnloadTexture(weapons);
	CSGD_TextureManager::GetInstance()->UnloadTexture(gas);
	CSGD_TextureManager::GetInstance()->UnloadTexture(pot);
	CSGD_TextureManager::GetInstance()->UnloadTexture(bigbow);
	CSGD_TextureManager::GetInstance()->UnloadTexture(bow);
	CSGD_TextureManager::GetInstance()->UnloadTexture(rock);
	CSGD_TextureManager::GetInstance()->UnloadTexture(castle1);
	CSGD_TextureManager::GetInstance()->UnloadTexture(castle2);
	CSGD_TextureManager::GetInstance()->UnloadTexture(castle3);
}

CTutorialState* CTutorialState::GetInstance()
{
	static CTutorialState instance;
	return &instance;
}

void CTutorialState::Render()
{ 
	CSGD_Direct3D* pD3D = CSGD_Direct3D::GetInstance();
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();
	VIN_BitMapFont* bf = VIN_BitMapFont::GetInstance(); 
	pTM->Draw(back, 0, 0);
	pTM->Draw(castle, 500, 145, 1.5f, 1.5f);
	pTM->Draw(background, 0, -1800, 2.0f, 2.0f);
	bf->Render("How to Play",250,25,1.7f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
	char buff[20];
	sprintf_s(buff, sizeof(buff), "%d of 5", Page + 1);
	switch(Page)
	{
	case 0:
		{
			bf->Render("Controls:",120,100,1,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("Protect your castle by using your cursor.",150,130,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("Pinch enemies by left clicking on them",150,155,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("Depending on the enemy's weight and your level,",150,185,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("you may pick them up",170,210,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(inHand,330,250,2,2);
			bf->Render("Swing the enemy with an upward or downward motion.",120,430,.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("  and release the left mouse button to let go.",120,460,.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("You can toss enemies into the air or smash into the ground.",120,490,.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
		}
		break;
	case 1:
		{
			bf->Render("Enemies:",120,140,1,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("Each enemy has a certain weight.",150,175,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("If your Level is heigh enough, you may be ",150,200,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("   able to pick up the enemy.",150,225,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("The following are arranged from lightest to heaviest",150,250,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(badguys,180,300);
			pTM->Draw(boom,150,420);
			bf->Render("Watch out for this guy.",250,450,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("he explodes and does massive damage",250,470,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("to your castle and nearby enemies.",250,490,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
		}
		break;
	case 2:
		{
			bf->Render("*All player weapons have cool downs*",150,100,1,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("It is shown with a bar under it's button",130,130,1,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);

			bf->Render("Castle Upgrades and Defenses:",100,200,1,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("When you kill enemies, Gold will drop. Pick it up",130,230,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("At times, just throwing enemies is not enough to win.",130,260,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("Hence, when overwhelmed by enemies use your defenses!",130,290,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("You can upgrade the Castle when you have enough money",130,320,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("The rock can also upgraded. Higher Lvl means more HP",130,350,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(weapons,120,400,1.2f,2);
		}
		break;
	case 3:
		{
			bf->Render("*Mouse over will show prices",225,95,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(gas,120,130);
			bf->Render("Sets cursor to the poison cloud. Alternatively press 2",200,130,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("This does AoE damage over time.",200,160,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(rock,120,220,0.4f,0.4f);
			bf->Render("Sets cursor to the boulder. Alternatively press 3",200,220,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("This can be dropped on and block enemies.",200,250,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(pot,120,300);
			bf->Render("The Boiling oil kills all attacking melee enemies.",200,300,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			//bf->Render("Costs 300g.",200,330,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(bigbow,120,390);
			bf->Render("The Ballista kills all attacking ranged enemies.",200,390,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			//bf->Render("Costs 300g.",200,420,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(bow,120,470);
			bf->Render("Hires Archers to help defend your castle.",200,470,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("Click Button to Hire Archers. Max of 10",200,500,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
		}
		break;
	case 4:
		{
			bf->Render("You can also upgrade your castle.",120,150,1,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("Click on the door to do so.",120,180,1,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(castle1,120,180,0.3f,0.3f);
			bf->Render("This is the default castle.",200,220,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(castle2,120,260,0.3f,0.3f);
			bf->Render("This Castle costs 1500g to upgrade,",200,280,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("decreases damage taken and refills health.",200,310,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			pTM->Draw(castle3,100,360,0.3f,0.3f);
			bf->Render("This Castle costs 5000g to upgrade,",200,380,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
			bf->Render("heavily decreases damage taken and refills health.",200,410,0.9f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);

			bf->Render("GOOD LUCK!",300,480,1.1f,D3DCOLOR_ARGB(255, 100, 0, 0),GAMEFONT);
		}
		break;
	}


	bf->Render("Press Escape to Play Game",100,550,1,D3DCOLOR_ARGB(255, 0, 0, 0),GAMEFONT);
	bf->Render("<----              ---->",490,545,1,D3DCOLOR_ARGB(255, 0, 0, 0),MENUFONT);
	bf->Render(buff,550,550,1,D3DCOLOR_ARGB(255, 0, 0, 0),GAMEFONT);

	
	
	
}

bool CTutorialState::Input()
{
	CSGD_DirectInput*	pDI = CSGD_DirectInput::GetInstance();
	CGame*				pGameState = CGame::GetInstance();

	if(InputManager::GetInstance()->Escape())
	{
		CMainMenuState::GetInstance()->game_scroll = true;
		CGame::GetInstance()->ChangeState( CMainMenuState::GetInstance());
	}

	if(InputManager::GetInstance()->MoveRight())
	{
		Page++;
		if(Page > 4)
			Page = 4;

	}

	if(InputManager::GetInstance()->MoveLeft())
	{
		Page--;
		if(Page < 0)
			Page = 0;
	}
	return true;
}

void CTutorialState::Update(float fElapsedTime)
{
	/*if(opt_scrolling)
	{
		m_nscroll = m_nscroll - (500 * fElapsedTime);

		if(m_nscroll <= -1050.0f)
		{
			m_nscroll = -1050.0f;
			opt_scrolling = false;
			CGame::GetInstance()->ChangeState(COptionsMenu::GetInstance());
		}
	}

	else if(main_scrolling)
	{
		m_nscroll = m_nscroll + (500 * fElapsedTime);
		if(m_nscroll >= -250.0f)
		{
			m_nscroll = -250.0f;
			main_scrolling = false;
		}
	}

	else if(main_scrolling2)
	{
		m_nscroll = m_nscroll - (600 * fElapsedTime);
		if(m_nscroll <= -250.0f)
		{
			m_nscroll = -250.0f;
			main_scrolling2 = false;
		}
	}

	else if(game_scroll)
	{
		m_nscroll = m_nscroll + (500 * fElapsedTime);
		if(m_nscroll >= 700)
		{
			m_nscroll = 700;
			game_scroll = false;
			CGame::GetInstance()->ChangeState(CGamePlayState::GetInstance());
		}
	}

	else if(credit_scroll)
	{
		m_nscroll = m_nscroll - (600 * fElapsedTime);
		if(m_nscroll <= -1800.0f)
		{
			m_nscroll = -1800.0f;
			credit_scroll = false;
			if(m_nSelection == 3)
				CGame::GetInstance()->ChangeState( CCreditsState::GetInstance());
			else if(m_nSelection == 2)
				CGame::GetInstance()->ChangeState( CHighScoreState::GetInstance());
				
		}
	}*/
}	